<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../css/orderset.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <style>
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }

        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>预约订单管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约订单管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <!-- 日期控件 -->
                <el-date-picker
                        v-model="pagination.queryDate"
                        type="daterange"
                        align="right"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        format="yyyy-MM-dd"
                        value-format="yyyy-MM-dd"
                        :default-time="['00:00:00', '23:59:59']"
                        :picker-options="pickerOptions">
                </el-date-picker>
                <!-- 预约类型 -->
                <el-select v-model="pagination.queryOrderType" placeholder="预约类型" style="width: 120px;" clearable
                           placeholder="请选择">
                    <el-option label="微信预约" value="微信预约"></el-option>
                    <el-option label="电话预约" value="电话预约"></el-option>
                </el-select>
                <!-- 预约状态 -->
                <el-select v-model="pagination.queryOrderState" placeholder="预约状态" style="width: 120px;" clearable
                           placeholder="请选择">
                    <el-option label="未到诊" value="未到诊"></el-option>
                    <el-option label="已到诊" value="已到诊"></el-option>
                </el-select>
                <!-- 套餐名称 -->
                <el-input placeholder="套餐名称" v-model="pagination.querySetmealName" style="width: 150px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>
                <!-- 会员姓名/手机号 -->
                <el-input placeholder="会员姓名/手机号" v-model="pagination.queryString" style="width: 150px;"
                          class="filter-item" @keyup.enter.native="handleFilter"></el-input>

                <el-button @click="selectByQuery()" class="dalfBut">查询</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">预约</el-button>
                <el-button type="primary" class="butT" @click="handleCreate()">清除</el-button>
            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="memberName" label="会员姓名" align="center"></el-table-column>
                <el-table-column prop="telephone" label="电话号码" align="center"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column  label="预约状态" align="center" >
                    <template slot-scope="scope">
                        <el-switch
                                v-model="scope.row.orderStatus"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                active-value="已到诊"
                                inactive-value="未到诊"
                                @change="changeSwitch(scope.row)">
                        </el-switch>
                        <span>{{ scope.row.orderStatus == '未到诊' ? '未到诊' : '已到诊'}}</span>
                    </template>


                </el-table-column>

                <el-table-column prop="setmealName" label="套餐名称" align="center"></el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>


            <!-- 电话预约标签弹层 -->
            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataAddFormFirst" :rules="rules" :model="formData" label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="telephone">
                                                <el-input v-model="formData.telephone"/>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="memberName">
                                                <el-input v-model="formData.memberName"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <el-radio-group v-model="setmealId" @change="radioChange">
                                                    <el-radio :label="c.id"><span></span></el-radio>
                                                </el-radio-group>
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <el-pagination
                                        small
                                        @current-change="handleSmallCurrentChange"
                                        :current-page="smallPagination.smallCurrentPage"
                                        :page-size="smallPagination.smallPageSize"
                                        layout="total, prev, pager, next"
                                        :total="smallPagination.smallTotal">
                                </el-pagination>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible=false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
            <!-- 编辑预约标签弹层 -->
            <div class="edit-form">
                <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form ref="dataEditFormFirst" :rules="rules" :model="this.editFormData"
                                         label-position="right"
                                         label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="手机号码" prop="telephone">
                                                <el-input v-model="editFormData.telephone"/>
                                            </el-form-item>
                                        </el-col>

                                        <el-col :span="12">
                                            <el-form-item label="预约日期" prop="orderDate">
                                                <el-date-picker
                                                        v-model="editFormData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期"
                                                        value-format="yyyy-MM-dd"
                                                >
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名" prop="memberName">
                                                <el-input v-model="editFormData.memberName"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐编码</th>
                                            <th>套餐名称</th>
                                            <th>套餐说明</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <el-radio-group v-model="setmealId" @change="radioChange">
                                                    <el-radio :label="c.id"><span></span></el-radio>
                                                </el-radio-group>
                                            </td>
                                            <td><label :for="c.id">{{c.code}}</label></td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                                <el-pagination
                                        small
                                        @current-change="handleToppingSmallCurrentChange"
                                        :current-page="smallPagination.smallCurrentPage"
                                        :page-size="smallPagination.smallPageSize"
                                        layout="total, prev, pager, next"
                                        :total="smallPagination.smallTotal">
                                </el-pagination>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</body>

<script>
    //手机校验正则表达式
    var reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
    var vue = new Vue({
        el: '#app',
        data: {
            activeName: 'first',            //添加/编辑窗口Tab标签名称
            pagination: {                   //分页相关属性
                currentPage: 1,             //当前页
                pageSize: 10,               //每页显示多少条
                total: 100,                 //总条数
                queryString: null,          //会员姓名/手机号
                queryMemberName: null,
                queryPhoneNumber: null,
                queryDate: null,             //查询日期
                querySetmealName: null,           //套餐名称
                queryOrderType: null,             //预约类型
                queryOrderState: null             //预约状态
            },
            smallPagination: {//小型分页相关属性
                smallCurrentPage: 1,
                smallPageSize: 2,
                smallTotal: 0
            },
            orderStatus : "已到诊",
            dataList: [],//预约列表数据
            formData: {},//表单数据
            editFormData:{},
            tableData: [],//新增和编辑表单中对应的检查项列表数据
            setmealId: null,//新增和编辑表单中检查项对应的复选框，基于双向绑定可以进行回显和数据提交
            orderId: null,//套餐的ID
            dialogFormVisible: false,//控制添加窗口显示/隐藏
            dialogFormVisible4Edit: false,//控制编辑窗口显示/隐藏
            rules: {
                telephone: [{required: true, message: '编码为必填项', trigger: 'blur'}],
            },
            //日期控件
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
        },
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
               console.log(this.editFormData);
                if (!(reg_tel.test(this.editFormData.telephone))) {
                    this.$message.error("手机号输入错误,请检查后重新录入!!");
                    return false;
                }
                //表单校验
                this.$refs['dataEditFormFirst'].validate((valid) => {
                    if (valid) {//校验成功
                        //发送异步请求
                        axios.post("/order/editOrder.do?setmealId=" + this.setmealId + "&orderId=" + this.orderId, this.editFormData).then((res) => {
                            if (res.data.flag) {//执行成功
                                //弹出提示信息
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                            } else {//执行失败
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {//不管成功还是失败，都重新分页查询
                            this.dialogFormVisible4Edit = false;
                            this.activeName = 'first';
                            this.findPage();
                            //不管成功与失败,都把orderId,变成null,方便下次编辑再次赋值
                            this.orderId = null;
                            this.editFormData = {};
                        })
                    } else {//校验失败
                        this.$message.error("数据校验失败,请检查您的输入信息是否正确!!!");
                    }
                });

            },
            //添加
            handleAdd() {
                if (!(reg_tel.test(this.formData.telephone))) {
                    this.$message.error("手机号输入错误,请检查后重新录入!!");
                    return false;
                }
                //校验表单
                this.$refs['dataAddFormFirst'].validate((valid) => {
                    if (valid) {//校验成功
                        //发送异步请求,查询套餐信息
                        axios.post("/order/addOrder_fxw.do?setmealId=" + this.setmealId, this.formData).then((res) => {
                            if (res.data.flag) {//执行成功
                                //弹出提示信息
                                this.$message({
                                    type: 'success',
                                    message: res.data.message
                                })
                            } else {//执行失败
                                //弹出错误信息
                                this.$message.error(res.data.message);
                            }
                        }).finally(() => {
                            this.findPage();
                            this.activeName = 'first';
                            this.dialogFormVisible = false;
                        });
                    } else {//校验失败
                        this.$message.error("数据校验失败,请检查您的输入信息是否正确!!!");
                    }
                })
            },
            //分页查询
            findPage() {
                //判断是否为空
                if (this.pagination.queryString != null) {
                    //判断是不是手机号  -- 如果满足手机号校验规则  --就赋值给手机号
                    if (reg_tel.test(this.pagination.queryString)) {
                        this.pagination.queryPhoneNumber = this.pagination.queryString;
                    } else {
                        //如果不满足,就认为是会员名搜索
                        this.pagination.queryMemberName = this.pagination.queryString;
                    }
                }
                //异步请求，所需的参数
                let param = {
                    //当前页数据
                    currentPage: this.pagination.currentPage,
                    //每页展示多少数据
                    pageSize: this.pagination.pageSize,
                    //查询条件
                    // 手机号
                    queryPhoneNumber: this.pagination.queryPhoneNumber,
                    //会员名
                    queryMemberName: this.pagination.queryMemberName,
                    //查询条件  日期
                    queryDate: this.pagination.queryDate,
                    //查询条件  预约类型
                    queryOrderType: this.pagination.queryOrderType,
                    //查询条件  预约状态
                    queryOrderState: this.pagination.queryOrderState,
                    //查询套餐  套餐名称
                    querySetmealName: this.pagination.querySetmealName,
                }
                //发送异步请求
                axios.post("/order/findPage.do", param).then((res) => {
                    //响应的数据赋值给数据模型
                    this.pagination.total = res.data.total;
                    this.dataList = res.data.rows;
                }).finally(() => {
                    //不管成功还是失败 都把手机号和会员名字重置
                    this.pagination.queryMemberName = null;
                    this.pagination.queryPhoneNumber = null;
                });
            },
            //小型分页查找
            findSmallPage() {
                //异步请求，所需的参数
                let smallParam = {
                    //当前页
                    smallCurrentPage: this.smallPagination.smallCurrentPage,
                    //每页显示多少条
                    smallPageSize: this.smallPagination.smallPageSize,
                }
                //发送异步请求,发送数据 当前页，每页显示多少条，
                axios.post("/setmeal/findAll_fxw.do", smallParam).then((res) => {
                    //响应的数据赋值给tableData
                    this.tableData = res.data.rows;
                    this.smallPagination.smallTotal = res.data.total;
                })

            },
            //小型置顶分页查找
            findToppingSmallPage(setmealId) {
                //异步请求，所需的参数
                let smallParam = {
                    //当前页
                    smallCurrentPage: this.smallPagination.smallCurrentPage,
                    //每页显示多少条
                    smallPageSize: this.smallPagination.smallPageSize,
                }
                //发送异步请求,发送数据 当前页，每页显示多少条，
                axios.post("/setmeal/findSetmealBySetmealId.do?setmealId=" + setmealId, smallParam).then((res) => {
                    //响应的数据赋值给tableData
                    this.tableData = res.data.rows;
                    this.smallPagination.smallTotal = res.data.total;
                });

            },
            // 重置表单
            resetForm() {
                //重置表单
                this.formData = {};
                //this.setmealId = null;
            },
            // 弹出添加窗口
            handleCreate() {
                //展示页面
                this.activeName = 'first';
                //开启添加弹窗
                this.dialogFormVisible = true;
                //小型分页查找套餐信息
                this.findSmallPage();
                //每次点击预约都是小型页面都是第一页
                this.smallPagination.smallCurrentPage = 1;
                //每次打开都重置表单
                this.resetForm();
            },
            // 弹出编辑窗口
            handleUpdate(row) {
                this.orderId = row.orderId;
                //展示页面
                this.activeName = 'first';
                //开启编辑弹窗
                this.dialogFormVisible4Edit = true;
                this.editFormData = row;
                this.smallPagination.smallCurrentPage = 1;
                this.setmealId = row.id;
                this.findToppingSmallPage(this.setmealId);
            },
            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.findPage();
            },
            //切换小型页码
            handleSmallCurrentChange(currentPage) {
                this.smallPagination.smallCurrentPage = currentPage;
                this.findSmallPage(this.dataList);
            },
            //切换小型置顶页码
            handleToppingSmallCurrentChange(currentPage) {
                this.smallPagination.smallCurrentPage = currentPage;
                this.findToppingSmallPage(this.setmealId);
            },
            // 删除
            handleDelete(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.post("/order/delete.do?id=" + row.id).then((res) => {

                    }).catch((r) => {
                        if (r.response.status == 403) {
                            this.$message.error("权限不足");
                        }
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //switch 开关改变触发时间
            changeSwitch(data){
                this.$confirm('此操作将修改用户的预约状态, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //发送异步请求,修改到诊状态
                    axios.post("/order/editOrderStatus.do", data).then((res) => {
                        if (res.data.flag) {//执行成功
                            this.$message({
                                type: 'success',
                                message: res.data.message
                            })
                        } else {//执行失败
                            //弹出错误信息
                            this.$message.error(res.data.message);
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消修改'
                    });
                });
            },
            //根据条件查询，回到初始页
            selectByQuery() {
                this.pagination.currentPage = 1;
                this.findPage();
            },
            //切换radio绑定值选中
            radioChange: function (val) {
                this.setmealId = val;
            }
        }
    })
</script>
</html>
